import request from "@/utils/request";
import { ProjectCheckInForm, CompleteProjectInfo, ProjectBindManagerForm, ProjectUpdateApplyForm } from "./types";
const currentSystem = localStorage.getItem("usertypeName");

/**
 * 新增项目
 *
 * @param data
 */
export function CreateProject(data: ProjectCheckInForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/create_project";
      break;
    case "Corp":
      url = "/api/v1/corp/project/create_project";
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/create_project";
      break;
    case "Manager":
      url = "/api/v1/manager/project/create_project";
      break;
    case "Commander":
      url = "/api/v1/commander/project/create_project";
      break;
    default:
      url = "/api/v1/sysuser/project/create_project";
  }
  return request({
    url: url,
    method: "post",
    data: data,
  });
}

/**
 * 修改项目
 *
 * @param data
 */
export function UpdateProject(data: ProjectCheckInForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/update_project/" + data.projectId;
      break;
    case "Corp":
      url = "/api/v1/corp/project/update_project/" + data.projectId;
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/update_project/" + data.projectId;
      break;
    case "Manager":
      url = "/api/v1/manager/project/update_project/" + data.projectId;
      break;
    case "Commander":
      url = "/api/v1/commander/project/update_project/" + data.projectId;
      break;
    default:
      url = "/api/v1/sysuser/project/update_project/" + data.projectId;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}
/**
 * 完善项目
 *
 * @param data
 */
export function GetCompleteProjectForm(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "Corp":
      url = `/api/v1/corp/project/complet_project/${id}/form`;
      break;
    case "Manager":
      url = `/api/v1/manager/project/complet_project/${id}/form`;
      break;
    default:
      url = `/api/v1/manager/project/complet_project/${id}/form`;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 完善项目
 *
 * @param data
 */
export function CompleteProjectInfo(id: number, data: CompleteProjectInfo) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/complet_project/" + id;
      break;
    case "Corp":
      url = "/api/v1/corp/project/complet_project/" + id;
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/complet_project/" + id;
      break;
    case "Manager":
      url = "/api/v1/manager/project/complet_project/" + id;
      break;
    case "Commander":
      url = "/api/v1/commander/project/complet_project/" + id;
      break;
    default:
      url = "/api/v1/sysuser/project/complet_project/" + id;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 绑定劳资专管员
 *
 * @param data
 */
export function BindManager(data: ProjectBindManagerForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/bind_manager";
      break;
    case "Corp":
      url = "/api/v1/corp/project/bind_manager";
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/bind_manager";
      break;
    case "Manager":
      url = "/api/v1/manager/project/bind_manager";
      break;
    case "Commander":
      url = "/api/v1/commander/project/bind_manager";
      break;
    default:
      url = "/api/v1/sysuser/project/bind_manager";
  }
  data.obviousPassword = data.password;
  data.password = data.password;
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 获取分页
 *
 * @param data
 */
export function QueryProjectPage(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/project_page";
      break;
    case "Corp":
      url = "/api/v1/corp/project/project_page";
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/project_page";
      break;
    case "Manager":
      url = "/api/v1/manager/project/project_page";
      break;
    case "Commander":
      url = "/api/v1/commander/project/project_page";
      break;
    default:
      url = "/api/v1/sysuser/project/project_page";
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取项目详情
 *
 * @param id
 */
export function GetProjectInfo(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/detail";
      break;
    case "Corp":
      url = "/api/v1/corp/project/detail";
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/detail";
      break;
    case "Manager":
      url = "/api/v1/manager/project/detail";
      break;
    case "Commander":
      url = "/api/v1/commander/project/detail";
      break;
    default:
      url = "/api/v1/sysuser/project/detail";
  }
  return request({
    url: url + `/${id}`,
    method: "get",
  });
}

/**
 * 获取项目基础信息详情
 *
 * @param id
 */
export function GetProjectBaseInfo(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/base_info";
      break;
    case "Corp":
      url = "/api/v1/corp/project/base_info";
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/base_info";
      break;
    case "Manager":
      url = "/api/v1/manager/project/base_info";
      break;
    case "Commander":
      url = "/api/v1/commander/project/base_info";
      break;
    default:
      url = "/api/v1/sysuser/project/base_info";
  }
  return request({
    url: url + `/${id}`,
    method: "get",
  });
}

/**
 * 获取项目表单数据
 *
 * @param id
 */
export function GetProjectForm(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/project/${id}/projectform`;
      break;
    case "Corp":
      url = `/api/v1/corp/project/${id}/projectform`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/project/${id}/projectform`;
      break;
    case "Manager":
      url = `/api/v1/manager/project/${id}/projectform`;
      break;
    case "Commander":
      url = `/api/v1/commander/project/${id}/projectform`;
      break;
    default:
      url = `/api/v1/sysuser/project/${id}/projectform`;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 获取删除项目
 *
 * @param id
 */
export function DeleteProject(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/delete";
      break;
    case "Corp":
      url = "/api/v1/corp/project/delete";
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/delete";
      break;
    case "Manager":
      url = "/api/v1/manager/project/delete";
      break;
    case "Commander":
      url = "/api/v1/commander/project/delete";
      break;
    default:
      url = "/api/v1/sysuser/project/delete";
  }
  return request({
    url: url + `/${id}`,
    method: "delete",
  });
}

/**
 * 同步项目(仅住建)
 *
 * @param id
 */
export function SyncProject(projectId: number) {
  return request({
    url: "/api/v1/cmssupportApi/syncProject" + `/${projectId}`,
    method: "put",
  });
}

/**
 * 推送项目(仅住建)
 *
 * @param id
 */
export function PublishProject(projectId: number) {
  return request({
    url: "/api/v1/cmssupportApi/publishProject" + `/${projectId}`,
    method: "post",
  });
}

/**
 * 审核项目
 *
 * @param id
 * @param auditStatus 0:待审核 1:通过 -1:不通过
 */
export function auditProject(id: any, data: any) {
  let url = "/api/v1/sysuser/project/auditProject/" + id;
  return request({
    url: url,
    method: "put",
    params: data,
  });
}

/**
 * 获取项目下拉列表
 */
export function GetPulldownList() {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/pulldown";
      break;
    case "Corp":
      url = "/api/v1/corp/project/pulldown";
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/pulldown";
      break;
    case "Manager":
      url = "/api/v1/manager/project/pulldown";
      break;
    case "Commander":
      url = "/api/v1/commander/project/pulldown";
      break;
    default:
      url = "/api/v1/sysuser/project/pulldown";
  }
  return request({
    url: url,
    method: "get",
  });
}
/**
 * 导入项目
 * @param data
 */
export function ImportProject(data: any) {
  let url = "/api/v1/sysuser/project/import_project";
  return request({
    url: url,
    method: "post",
    data: data,
  });
}

/**
 * 判断是否存在更新申请
 */
export function ExistsUpdateApply(projectId: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/exists_update_apply/" + projectId;
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/exists_update_apply/" + projectId;
      break;
    default:
      url = "/api/v1/manager/project/exists_update_apply/" + projectId;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 获取更新申请信息
 */
export function UpdateApplyInfo(projectId: number) {
  let url = "/api/v1/constructor/project/update_apply_info/" + projectId;
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/update_apply_info/" + projectId;
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/update_apply_info/" + projectId;
      break;
    default:
      url = "/api/v1/constructor/project/update_apply_info/" + projectId;
  }
  return request({
    url: url,
    method: "get",
  });
}
/**
 * 审核更新申请
 * @param data
 */
export function AuditUpdateProjectApply(projectId: number, data: { auditType: number }) {
  let url = "/api/v1/constructor/project/update_apply_audit";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/update_apply_audit/" + projectId;
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/update_apply_audit/" + projectId;
      break;
    default:
      url = "/api/v1/constructor/project/update_apply_audit/" + projectId;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 创建更新申请
 * @param data
 */
export function CreateUpdateProjectApply(projectId: number, data: ProjectUpdateApplyForm) {
  let url = "/api/v1/manager/project/update_apply/" + projectId;
  return request({
    url: url,
    method: "post",
    data: data,
  });
}

/**
 * 重置劳资专管员密码
 * @param id
 * @returns
 */
export function ResetManagerPassWord(id: number, value: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "/api/v1/sysuser/project/resetManagerPassWord";
      break;
    case "Corp":
      url = "/api/v1/corp/project/resetManagerPassWord";
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/resetManagerPassWord";
      break;
    case "Manager":
      url = "/api/v1/manager/project/resetManagerPassWord";
      break;
    case "Commander":
      url = "/api/v1/commander/project/resetManagerPassWord";
      break;
    default:
      url = "/api/v1/sysuser/project/resetManagerPassWord";
  }
  return request({
    url: url + `/${id}`,
    method: "put",
    params: {
      password: encryptSM3(value),
      obviousPassword: value,
    },
  });
}
